package com.shelpe.services.sinbad.repository.jpa;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import com.shelpe.services.sinbad.entity.jpa.AutoProductQueue;

public interface AutoProductQueueRepository
		extends CrudRepository<AutoProductQueue, AutoProductQueue.QueuePK>, JpaSpecificationExecutor<AutoProductQueue> {

	List<AutoProductQueue> findByAdgroupIDInAndInitialKeywordCountGreaterThan(List<Long> adgroupIDs, int keywordCount);

	List<AutoProductQueue> findByCampaignID(long campaignID);
	
	List<AutoProductQueue> findByCampaignIDAndStatusIn(long campaignID, List<AutoProductQueue.Status> status);
	
//	List<AutoProductQueue> deleteByProductIDIn(List<Long> productID);
	
	@Query("select distinct po.productID from auto_pro_product_queue po where po.campaignID = ? and po.status = ?")
	List<Long> findProductIDsByCampaignID(Long campaignID,AutoProductQueue.Status status);
	
	@Transactional
	@Modifying
	@Query("delete from auto_pro_product_queue u where u.productID IN :ids")
	int deleteByProductIDIn(@Param("ids") List<Long> productID);
}
